package com.code.generator.db;

import java.sql.Connection;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.code.generator.entity.ColumnsEntity;
import com.code.generator.entity.TableEntity;
import com.code.view.ViewConstant;


/**
 * 数据库连接适配
 *
 *
 * @author 朱国军
 * @version 2015年3月13日 朱国军
 */
public class ConnectionFactory implements DataBaseConnection {
    private DataBaseConnection dataBaseConnection;


    /**
     * 构造函数
     *
     * @param dbDriver 数据库驱动
     */
    public ConnectionFactory(String dbDriver) {
        if (StringUtils.equals(ViewConstant.DB_DRIVER_ORACLE, dbDriver)) {
            dataBaseConnection = new OracleConnection();
        } else {
            dataBaseConnection = new MySqlConnection();
        }
    }


    @Override
    public Connection getConnection(String dbUser, String dbPassword, String dbDriver, String dbUrl) throws Exception {
        return dataBaseConnection.getConnection(dbUser, dbPassword, dbDriver, dbUrl);
    }


    @Override
    public List<ColumnsEntity> getColumnsEntity(Connection conn, String tableName, String dbUser) throws Exception {
        return dataBaseConnection.getColumnsEntity(conn, tableName, dbUser);
    }


    @Override
    public TableEntity getTableEntity(Connection conn, String tableName) throws Exception {
        return dataBaseConnection.getTableEntity(conn, tableName);
    }

}
